<?php 
	require_once("includes/connect.php");
	require_once("includes/function.php");

	$val = $_REQUEST["val"];

	$val1 = explode(",", $val);
	$val1 = implode("','",$val1);
	//$val = explode(",", $val);
	//$val = implode("','",$val);
?>

<script type="text/javascript">
	$(document).ready(function(){
		$("#i_date").datepicker({
			dateFormat: "yy-mm-dd",
			showButtonPanel: true
		 });

		$("#save_menus").click(function() {
			event.preventDefault();

			var branch_name = $("#branch_name").val();
			var bank_name = $("#bank_name").val();
			var cheque_no = $("#cheque_no").val();
			var i_date = $("#i_date").val();
			var val = "<?php echo $val; ?>";
			var task = "print";
	
			
			$.ajax({
				type: "POST",
				url: "process_status_welfare.php",
				data: { task: task, branch_name: branch_name, bank_name: bank_name, cheque_no: cheque_no, val: val, i_date:i_date },
				cach: false,
				error: function() {
					alert("ERROR !!!!");
				},
				success: function(data){
					//alert(data);
					//if(data) { $("#kob").html(data); }
					window.location.href="index.php?pages=cheque_welfare";
					//window.location.href="prt_cheque_welfare.php?cheque_no=" + cheque_no + "&val=" + val;
				}
			});
			

		});
	});
</script>
<?php
	$db = new myDBS;
	$db->selectDB("account");

	$result = $db->showData("bank");

	//$val = explode(",", $val);

	$sql = "SELECT SUM(welfare) as sum FROM tbl_welfare WHERE pet_id IN('$val1')";
	//echo $sql;
	$result1 = $db->runSQL($sql);
	$rows2 = $db->fetch_object($result1);
	
?>

<p>
	<label>วันที่</label>
	<input class="span3" type="text" id="i_date" name="i_date" />
	<label>จำนวนเงิน</label>
	<input class="span3" type="text" id="sum" name="sum" value="<?php echo number_format($rows2->sum,2); ?>" readonly>
	
    <label>ธนาคาร</label>
	<select class="span5" id="bank_name" name="bank_name" >
	<?php 
		while($rows = $db->fetch_object ( $result )) {
			echo "<option>$rows->bank_name</option>";
		}
	?>

	</select>
	<label>สาขา</label>
	<select class="span4" id="branch_name" name="branch_name" >
	<?php
		$result = $db->showData("branch");

		while($rows = $db->fetch_object ( $result )) {
			echo "<option>$rows->branch_name</option>";
		}

	?>
	</select>
	<label>เลขที่เช็ค</label>
	<input class="span2" type="text" id="cheque_no" name="cheque_no">

	
</p>
<div class="form-actions">
	<button class="btn btn-primary" id="save_menus">บันทึกและพิมพ์เช็ค</button>
	<a class="btn close-dialog"><i class="icon-remove"></i> ยกเลิก</a>

</div>
